package com.lichuandi.controller;

import com.lichuandi.entity.Article;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.query.IndexQuery;
import org.springframework.data.elasticsearch.core.query.IndexQueryBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;


@RestController
public class ElasticOperationController {

    @Autowired
    private ElasticsearchTemplate template;

    @GetMapping("createIndex")
    public void createIndex(String indexName){
        // return elasticsearchTemplate.index(indexName);
      /*  Article article = new Article();
        article.setArticleName(indexName);
        IndexQueryBuilder indexQueryBuilder = new IndexQueryBuilder().withIndex(indexName);
        IndexQuery build = indexQueryBuilder.withObject(article).build();


        template.index(indexQueryBuilder);*/


    }

    @GetMapping("deleteIndex")
    public boolean deleteIndex(String indexName){
        //return template.deleteIndex(indexName);
        return false;
    }

    @GetMapping("indexIsExist")
    public boolean indexIsExist(String indexName){
       // return template.indexExists(indexName);
        return  false;
    }

    @GetMapping("typeIsExist")
    public boolean typeIsExist(String indexName,String type){
       // return template.typeExists(indexName,type);
        return false;
    }

    @GetMapping("getMapping")
    public Map getMapping(String indexName, String type){
        //return template.getMapping(indexName,type);
        return new HashMap<>();
    }

    @GetMapping("getSetting")
    public Map getSetting(String indexName){
       // return template.getSetting(indexName);
        return new HashMap<>();
    }
}
